Imports MindFusion.Diagramming

Public Module ModBase
    'represents base enumerations and operations

#Region "Public Attributes"
    Public Const GsStringNullValue As String = ""
    Public Const GsStringDefaultValue As String = ""
    Public Const GiIntegerDefaultValue As Integer = -1
#End Region
#Region "Enums"
    'result of action
    Public Enum GeActionResult
        kkOk = 1 'OK
        kkCancel = 2 'cancel
        kkError = 3 'eroor

        kkTABLEDuplicityOfNameOfTable = 100 'duplicity of name of table 

        kkROWOFTABLEDuplicityOfNameOfRow = 200 'duplicity of name of table row
        kkROWOFTABLENoRowsToChange = 201 'no table rows to change

        kkAMODAccessFileError = 300 'error while accessing file
    End Enum
    'position of new row enum
    Public Enum GePositionOfNewRow
        kkFirst = 1
        kkLast = 2
        kkSpecified = 3
    End Enum
    'images index enum
    Public Enum GeImagesIndex
        kkClass = 0
        kkMethod = 1
        kkProperty = 2
        kkField = 3
        kkLink = 4
    End Enum
    'primary operation of hand enum
    Public Enum GePrimaryOperationOfHand
        kkNeutral = 0
        kkTable = 1
        kkContainer = 2
        kkNote = 3
    End Enum
    'type of link
    Public Enum GeTypeOfLink
        kkRelationship = 0 'relationship between tables
        kkNote = 1 'link between notes or note and any object
    End Enum
    'secondary operation of hand enum
    Public Enum GeSecondaryOperationOfHand
        kkIdle = 1
        kkZoom = 2
    End Enum
    '' ''types of links
    ' ''Public Enum GeTypeOfLink
    ' ''    'used also for type of links ->>
    ' ''    kkLink1a01 = 0
    ' ''    kkLink1a1 = 1
    ' ''    kkLink1a1N = 2
    ' ''    kkLink1aN = 3
    ' ''    'used also for type of links <<-
    ' ''End Enum
    'edge of shape enum for link
    Public Enum GeEdgeForLink
        kkNoEdge = 1
        kkLeft = 2
        kkTop = 3
        kkRight = 4
        kkBottom = 5
    End Enum
    'edge of shape enum for resize of node
    Public Enum GeEdgeForResize
        kkNoEdge = 1
        kkLeft = 2
        kkTop = 3
        kkRight = 4
        kkBottom = 5
        kkTopLeftCorner = 6
        kkTopRightCorner = 7
        kkBottomRightCorner = 8
        kkBottomLeftCorner = 9
    End Enum
    'cursor operation based on cursor coordinates
    Public Enum GeCursorOperation
        kkSelectionRectangle = 1

        kkLinkCreate = 2
        kkTableCreate = 3
        kkContainerCreate = 4

        kkLinkMove = 10
        kkTableMove = 11
        kkContainerMove = 12
        kkShapeNodeMove = 13

        kkTopLeftCornerModification = 100
        kkTopRightCornerModification = 101
        kkBottomRightCornerModification = 102
        kkBottomLeftCornerModification = 103
        kkTopCenterModification = 104
        kkMiddleRightModification = 105
        kkBottomCenterModification = 106
        kkMiddleLeftModification = 107
    End Enum
    'state of file
    Public Enum GeFileState
        kkNotInit = 0 'not initialized file (uknown path + not editable)
        kkNewFile = 1 'new file(uknown path + editable)
        kkReady = 2 'initialized file (known path + ready to use)
        kkOpened = 3 'opened file (known path + in use)
    End Enum
    'type of item to drag&drop
    Public Enum GeTypeOfDragDropItem
        kkNone = 0 'none action
        kkTable = 1 'table
        kkContainer = 2 'container
        kkNote = 3 'note
        kkTemplateTable = 4 'template of table
    End Enum
    'type of popup menu
    Public Enum GeTypeOfPopupMenu
        kkNodeContext = 0 'menu for node in diagram
        kkUnitContext = 1 'menu for unit in diagram
    End Enum
#End Region
#Region "Functions"
    'is item in collection?
    Public Function IsInCollection(ByVal IoCollection As Collection, ByVal IsKey As String) As Boolean
        Try
            If IoCollection(IsKey) IsNot Nothing Then
                Return True
            End If
        Catch ex As Exception
            Return False
        End Try
    End Function
    'converts PointF to Point
    Public Function PoitFtoPoint(ByVal IoPointF As PointF) As Point
        Return New Point(CInt(IoPointF.X), CInt(IoPointF.Y))
    End Function
    'gets error text from error code
    Public Function TranslateError(ByVal IeActionResult As GeActionResult) As String
        Select Case IeActionResult
            Case GeActionResult.kkOk, GeActionResult.kkCancel
                Return ""
            Case GeActionResult.kkError
                Return "Nastala chyba: "
            Case GeActionResult.kkTABLEDuplicityOfNameOfTable
                Return "Tabulka s uvedenym nazvom uz existuje!"
            Case GeActionResult.kkROWOFTABLEDuplicityOfNameOfRow
                Return "Riadok so zadanym nazvom uz v tabulke existuje!"
            Case GeActionResult.kkAMODAccessFileError
                Return "Chyba pri pristupe k suboru!"
            Case Else
                Debug.Print("CHYBA!!! - TranslateError - neuvedeny index akcie")
                Return ""
        End Select
    End Function
    'gets application path
    Public Function GetApplicationPath() As String
        Return System.AppDomain.CurrentDomain.BaseDirectory
    End Function
    'gets EXE name
    Public Function GetApplicationExeName() As String
        Return System.AppDomain.CurrentDomain.FriendlyName
    End Function
    'gets icon index for type of column in table from kkXmodColumnTypes enum 
    Public Function GetIconIndexForTypeOfColumn(ByVal IeColumnType As kkXmodColumnTypes) As Integer
        Select Case IeColumnType
            Case kkXmodColumnTypes.kkBoolean
                Return 0
            Case kkXmodColumnTypes.kkInt32
                Return 1
            Case kkXmodColumnTypes.kkDecimal
                Return 2
            Case kkXmodColumnTypes.kkText
                Return 3
            Case kkXmodColumnTypes.kkDatum
                Return 4
            Case kkXmodColumnTypes.kkCas
                Return 5
            Case kkXmodColumnTypes.kkDatetime
                Return 6
            Case Else
                Debug.Print("CHYBA!!! - GetIconIndexForTypeOfColumn")
        End Select
    End Function
#End Region
#Region "Subs"
    'shows error message based on result of action
    Public Sub ShowErrorMessageFromEnum(ByVal IeActionResult As GeActionResult, Optional ByVal IsAdditionalText As String = "")
        Select Case IeActionResult
            Case GeActionResult.kkOk, GeActionResult.kkCancel
            Case Else
                ShowErrorMessage(TranslateError(IeActionResult) & " " & IsAdditionalText)
        End Select
    End Sub
    'shows message
    Public Sub ShowErrorMessage(ByVal IsText As String, Optional ByVal IsCaption As String = "Aplikacia")
        MessageBox.Show(IsText, IsCaption, MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Sub
#End Region

End Module
